﻿using Basic.FormGatewaryModular.Interface;
using Basic.FormGatewaryModular.Model.PageLayout;
using Basic.FormRemoteModel.PageBody.Model;
using Basic.FormRemoteModel.PageLayout.Model;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Basic.FormGatewaryModular.Api
{
    [ApiRouteName("/form/page/layout/{name}")]
    internal class PageLayoutApi : ApiController
    {
        private readonly IPageLayoutService _Service;
        private readonly ICustomPageService _CustomPage;
        public PageLayoutApi ( IPageLayoutService service, ICustomPageService customPage )
        {
            this._CustomPage = customPage;
            this._Service = service;
        }
        public PageLayoutForm[] GetForm ( [NumValidate("form.page.id.error", 1)] long pageId )
        {
            return this._Service.GetForm(pageId);
        }
        public PageControlDto Move ( MovePage param )
        {
            this._Service.Move(param.Id, param.ParentId);
            return this._CustomPage.GetLayout(param.Id, param.IsEdit);
        }
        public PageLayoutBase Add ( PageLayoutAdd add )
        {
            return this._Service.Add(add);
        }

        public void Delete ( [NumValidate("form.page.layout.id.error", 1)] long id )
        {
            this._Service.Delete(id);
        }

        public PageLayoutData Get ( [NumValidate("form.page.layout.id.error", 1)] long id )
        {
            return this._Service.Get(id);
        }

        public void SaveSort ( LongNullParam<int>[] sort )
        {
            this._Service.SaveSort(sort.ToDictionary(a => a.Id, a => a.Value));
        }

        public bool Set ( LongParam<PageLayoutSet> set )
        {
            return this._Service.Set(set.Id, set.Value);
        }
    }
}
